home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #2 / Ham Radio 2000 - Volume 2.iso / HAMV2 / ANTENNA / YAGIU112 / READ_DAT.C < prev    next >
C/C++ Source or Header  |  1995-08-18  |  2KB  |  77 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include "yagi.h"
  4.  
  5. void read_yagi_data(char *one_line, char *input_filename, double *frequency, double *min_frequency, double *max_frequency, double *step_frequency, int driven , double **d, int parasitic, double **p, double *angular_step)
  6. {
  7.     FILE *ifp;
  8.     char *null, *tmp;
  9.     int i;
  10.  
  11.     null=string(0L,MAX_LINE);
  12.  
  13.     tmp=string(0L,MAX_LINE);
  14.     ifp=fopen(input_filename, "rt");
  15.     if(ifp == NULL)
  16.     {
  17.         fprintf(stderr,"Sorry, cant find file:  %s\n", input_filename);
  18.         exit(2);
  19.     }
  20.     /* Read one_line by one_line, looking for data on the elements */
  21.     while(!feof(ifp))
  22.     {
  23.         fgets(one_line, MAX_LINE-1, ifp);
  24.  
  25.         if(strncmp(one_line,"STEP_FREQUENCY",14) == 0)  
  26.         {
  27.             sscanf(one_line,"%s %lf", null, step_frequency);
  28.             *step_frequency*=1e6;
  29.         }
  30.         if(strncmp(one_line,"MIN_FREQUENCY",13) == 0)  
  31.         {
  32.             sscanf(one_line,"%s %lf", null, min_frequency);
  33.             *min_frequency*=1e6;
  34.         }
  35.         if(strncmp(one_line,"MAX_FREQUENCY",13) == 0)  
  36.         {
  37.             sscanf(one_line,"%s %lf", null, max_frequency);
  38.             *max_frequency*=1e6;
  39.         }
  40.         if(strncmp(one_line,"ANGULAR_STEP",12) == 0)  
  41.         {
  42.             sscanf(one_line,"%s %lf", null, angular_step);
  43.         }
  44.         if(strncmp(one_line,"FREQUENCY",9) == 0)  
  45.         {
  46.             sscanf(one_line,"%s %lf", null, frequency);
  47.             *frequency*=1e6;
  48.         }
  49.         if(strncmp(one_line,"DATA_PARASITIC",14) == 0)  
  50.         {
  51.             one_line+=14;
  52.             for(i=1;i<=parasitic; ++i)
  53.             {
  54.                 fgets(one_line, MAX_LINE-1, ifp);
  55.                 sscanf(one_line,"\n%lf %lf %lf %lf",&p[i][X], &p[i][Y], &p[i][LENGTH], &p[i][DIAMETER] );
  56.             }
  57.         }
  58.         if(strncmp(one_line,"DATA_DRIVEN",11) == 0)  
  59.         {
  60.             one_line+=11; /* skip DATA_DRIVEN */
  61.             for(i=1;i<=driven; ++i)
  62.                 sscanf(one_line, "%lf %lf %lf %lf %lf %lf\n", &d[i][X], &d[i][Y], &d[i][LENGTH], &d[i][DIAMETER], &d[i][VOLTAGE_R], &d[i][VOLTAGE_I]);
  63.         }
  64.     }
  65.     fclose(ifp);
  66.     if(*min_frequency > *max_frequency || *angular_step <= 0 || *step_frequency <=0.0 || *frequency <=0.0 )
  67.     {
  68.         fprintf(stderr,"Error in input file %s. Please check:\n", input_filename);
  69.         fprintf(stderr,"FREQUENCY, MIN_FREQUENCY, MAX_FREQUENCY, STEP_FREQUENCY and ANGULAR_STEP\n");
  70.         exit(1);
  71.     }
  72.  
  73.     free_string(null,0L,MAX_LINE); 
  74.     free_string(tmp,0L,MAX_LINE); 
  75. }
  76.  
  77.